<template>
  <div class="top-info flex-center">
    <div class="numbers">
      <span>已删除的问卷（{{ delSurvey.length }}）</span>
    </div>
  </div>
  <div class="survey-area">
    <div class="wrap">
      <div class="survey-item" v-for="survey in delSurvey" @mouseleave="$event.currentTarget.classList.remove('hover')" @mouseenter="$event.currentTarget.classList.add('hover')" :key="survey.id">
        <span class="tag over">已删除</span>
        <ul class="survey-item__config">
          <li>
            <span>{{ survey.collect_num }} 份</span>
          </li>
          <li>
            <span>{{ survey.time_format }}</span>
          </li>
          <li><button @click="restore(survey.id)">恢复</button></li>
        </ul>
        <div class="survey-item__title">
          <p>{{ survey.title }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import getDeletedSurvey from '@/request/getDeletedSurvey'
import restoreSurvey from '@/request/restoreSurvey'

export default {
  data() {
    return {
      delSurvey: []
    }
  },
  methods: {
    async restore(id) {
      if (window.confirm('确定恢复该问卷？')) {
        const status = await restoreSurvey(id)
        if (!status) {
          this.$msg('恢复失败', 'error')
          return
        }
        this.delSurvey = await getDeletedSurvey()
      }
    },
  },
  async mounted() {
    this.delSurvey = await getDeletedSurvey()
  },
}
</script>

<style lang="scss">
.top-info {
  height: 50px;
  padding: 10px 30px;
  display: flex;
  align-items: center;
  justify-content: flex-start;

  .numbers {
    flex: none;
    width: max-content;
    margin-right: 20px;
    font-weight: bold;
  }
  .radio-sort {
    flex: none;
    display: flex;
    align-items: center;
    user-select: none;

    div {
      width: 100px;
      height: 34px;
      margin: 0 10px;
      position: relative;

      input {
        width: 100%;
        height: 100%;
        display: block;
        opacity: 0;
        position: absolute;
      }
      label {
        display: block;
        width: 100%;
        height: 100%;
        display: grid;
        place-content: center;
        background-color: #fff;

        font-size: 14px;
        color: #333;
        border-radius: 4px;
        box-shadow: 0 0 4px 0 #ddd;
      }
      input:checked + label {
        background-color: skyblue;
        color: #fff;
      }
    }
  }
}

.survey-area {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding-bottom: 40px;
  flex: 1 0 auto;
  .wrap {
    padding: 18px 30px;
    .survey-item {
      width: 100%;
      min-width: max-content;
      padding: 10px;
      margin: 0 16px 32px 0;
      position: relative;

      background-color: #fff;
      box-shadow: 0px 2px 8px rgb(0 0 0 / 6%);
      border-radius: 4px;

      span.tag {
        position: absolute;
        z-index: 11;
        top: 10px;
        left: -5px;
        --h: 24px;
        width: 70px;
        font-size: 12px;

        color: #fff;
        background-color: #1ed261;
        &.over {
          color: #fff;
          background-color: #d2361e;
        }
      }

      .survey-item__config {
        padding: 0 70px;
        padding-bottom: 10px;
        display: flex;
        align-items: center;

        li {
          width: max-content;
          min-width: max-content;
          margin-right: 20px;
          button {
            border: none;
            font-size: 15px;
            cursor: pointer;
            &:hover {
              color: #0f6bff;
              filter: brightness(1.1);
            }
            &:active {
              filter: brightness(0.9);
            }
          }
          a:hover {
            color: #0f6bff;
          }
        }
        li.li-svg {
          display: flex;
          align-items: center;
          cursor: pointer;
          span {
            cursor: inherit;
            line-height: 20px;
            margin-left: 4px;
          }
          &:hover span {
            color: #0f6bff;
            fill: #0f6bff;
          }
        }
      }
      .survey-item__title {
        width: 100%;
        padding: 0 20px;
        p {
          width: 90%;
          word-wrap: break-word;
        }
      }
    }
  }
}
</style>
